function t(t, o) {
    return t + o;
}

function o(t) {
    return Array.from(t).map(function(t) {
        return {
            x: t.pageX,
            y: t.pageY
        };
    });
}

function s(t) {
    return Array.prototype.slice.call(t.touches).map(function(t) {
        return {
            x: t.pageX,
            y: t.pageY
        };
    });
}

function e(t, o) {
    var s, e;
    return s = t.x - o.x, e = t.y - o.y, Math.sqrt(s * s + e * e);
}

function n(t, o) {
    var s = e(t[0], t[1]);
    return e(o[0], o[1]) / s;
}

function r(t) {
    return i(t);
}

function i(o) {
    return {
        x: o.map(function(t) {
            return t.x;
        }).reduce(t) / o.length,
        y: o.map(function(t) {
            return t.y;
        }).reduce(t) / o.length
    };
}

var a = function(t) {
    this.vm = t, this.zoomFactor = 1, this.offset = {
        x: 0,
        y: 0
    };
};

a.prototype = {
    touchstart: function(t) {
        2 === t.touches.length && (this.started = !0, this.firstMove = !0, this.nthZoom = 0, 
        this.lastScale = 1, this.lastZoomCenter = !1);
    },
    touchmove: function(t) {
        this.started && 2 === t.touches.length && (this.firstMove ? this.startTouches = o(t.touches) : (this.handleZoom(t, n(this.startTouches, o(t.touches))), 
        this.update()), this.firstMove = !1);
    },
    update: function() {
        var t = this.zoomFactor, o = "transform-origin: 0% 0%;transform:scale3d(" + t + ", " + t + ",1) translate3d(" + -this.offset.x / t + "px," + -this.offset.y / t + "px,0px)";
        this.vm.setData({
            transform3d: o
        });
    },
    touchend: function(t) {
        this.started = !1;
    },
    handleZoom: function(t, o) {
        var e = r(s(t)), n = o / this.lastScale;
        this.lastScale = o, this.nthZoom += 1, this.nthZoom > 3 && (this.scale(n, e), this.drag(e, this.lastZoomCenter)), 
        this.lastZoomCenter = e;
    },
    scale: function(t, o) {
        t = this.scaleZoomFactor(t), this.addOffset({
            x: (t - 1) * (o.x + this.offset.x),
            y: (t - 1) * (o.y + this.offset.y)
        });
    },
    scaleZoomFactor: function(t) {
        var o = this.zoomFactor;
        return this.zoomFactor *= t, this.zoomFactor = Math.min(4, Math.max(this.zoomFactor, .5)), 
        this.zoomFactor / o;
    },
    addOffset: function(t) {
        this.offset = {
            x: this.offset.x + t.x,
            y: this.offset.y + t.y
        };
    },
    drag: function(t, o) {
        o && this.addOffset({
            y: -(t.y - o.y),
            x: -(t.x - o.x)
        });
    },
    reset: function() {
        this.zoomFactor = 1, this.offset = {
            x: 0,
            y: 0
        }, this.update();
    }
}, module.exports = a;